package com.example.sunjian.myapplication.edittext;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.sunjian.myapplication.R;

/**
 * 作者：sunjian on 16/6/30 14:38
 * 邮箱：sunjian@cyhz.com
 */
public class EditTextActivity extends Activity {


    private EditText mTxt;
    private Button mBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_txt);
        mTxt=(EditText)findViewById(R.id.et);
        mBtn=(Button)findViewById(R.id.btn);
        mBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Editable editable = mTxt.getText();
                int start = mTxt.getSelectionStart();
                int end = mTxt.getSelectionEnd();
                Log.e("sj","start--->"+start+"    end:"+end);//start end 相等
                editable.insert(start,"测试");
            }
        });
    }
}
